package com.zzw.hj88;

import java.util.*;

/**
 * @Project: hw_java
 * @Description: 扑克牌大小
 * @Author: zzw
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextLine()) {
            String[] strs = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "joker", "JOKER"};
            List pks = Arrays.asList(strs);
            String s = scan.nextLine();
            String b = s.substring(0, s.indexOf("-"));
            String f = s.substring(s.indexOf("-") + 1);
            String res = "ERROR";
            String[] bs = b.split(" ");
            String[] fs = f.split(" ");
            int blen = bs.length;
            int flen = fs.length;
            if (blen == flen) {
                res = pks.indexOf(bs[0]) > pks.indexOf(fs[0]) ? b : f;
            } else {
                if ("joker".equals(bs[0])) res = b;
                if ("joker".equals(fs[0])) res = f;
                if (!"joker".equals(bs[0]) && !"joker".equals(fs[0])) {
                    if (blen == 4) res = b;
                    if (flen == 4) res = f;
                }
            }
            System.out.println(res);
        }
    }
}